#include "RsGisLibClbCalNadImgViewAngle.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibClbCalNadImgViewAngle::RsGisLibClbCalNadImgViewAngle(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibClbCalNadImgViewAngle();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_CalNadImgViewAngle, SIGNAL(clicked()), this, SLOT(on_action_Button_CalNadImgViewAngle_clicked()));

	ui->textBrowser_ParameterDescription->setText(
		"altitude - is a float in metres for the satellite altitude\nmin_xx_col - is a string for the minXX column in the RAT\nmin_xy_col - is a string for the minXY column in the RAT\nmax_xx_col - is a string for the maxXX column in the RAT\nmax_xy_col - is a string for the maxXY column in the RAT\nmin_yx_col - is a string for the minYX column in the RAT\nmin_yy_col - is a string for the minYY column in the RAT\nmax_yx_col - is a string for the maxYX column in the RAT\nmax_yy_col - is a string for the maxYY column in the RAT\nGdal Format - string specifying the output image format"
	);

	ui->textBrowser_ParameterDescription->setEnabled(false);

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\LT51200352005057BJC01.tif");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestCalNadImgViewAngle.tif");
	ui->lineEdit_minXXCol->setText("minXXcol");
	ui->lineEdit_maxXXCol->setText("maxXXcol");
	ui->lineEdit_minYYCol->setText("minYYcol");
	ui->lineEdit_maxYYCol->setText("maxYYcol");
	ui->lineEdit_minXYCol->setText("minXYcol");
	ui->lineEdit_maxXYCol->setText("maxXYcol");
	ui->lineEdit_minYXCol->setText("minYXcol");
	ui->lineEdit_maxYXCol->setText("maxYXcol");
	ui->lineEdit_Altitude->setText("0.0");
	ui->lineEdit_GdalFormat->setText("GTIFF");

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibClbCalNadImgViewAngle::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalNadImgViewAngle::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibClbCalNadImgViewAngle::on_action_Button_CalNadImgViewAngle_clicked()
{
	{
		if (ui->lineEdit_InputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Input File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_minXXCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "min XX Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_maxXXCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "max XX Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_minYYCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "min YY Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_maxYYCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "max YY Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_minXYCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "min XY Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_maxXYCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "max XY Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_minYXCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "min YX Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_maxYXCol->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "max YX Col is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Altitude->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Altitude is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("imageCalibration"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("CalNadImgViewAngle"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_minXXCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_maxXXCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_minYYCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_maxYYCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_minXYCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_maxXYCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_minYXCol->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_maxYXCol->text()));
	AlgParaList << QVariant(double(ui->lineEdit_Altitude->text().toDouble()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}
